package cn.wolfcode.wms.web.controller;


import cn.wolfcode.wms.service.IEmployeeService;
import cn.wolfcode.wms.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

//登陆检查
@Controller
public class LoginController {

    @Autowired
    private IEmployeeService employeeService;

    @ResponseBody
    @RequestMapping("login")
    //界面使用了ajax请求来发送请求,对应的后台需要返回一个JSON对象作为响应
    public Object login(String username,String password){
        JSONResult jsonResult = new JSONResult();
        try{
            employeeService.userLoginCheck(username,password);

        }catch (Exception e){
            e.printStackTrace();
            //把错误信息保存到JSONResult中(getMessage表示错误信息)
            jsonResult.mark(e.getMessage());
        }

       return jsonResult;
    }

    @RequestMapping("main")
    public String main(){

        return "main";
    }

    //退出系统界面
    @RequestMapping("logout")
    public String removeSession(HttpSession session){
        //销毁session对象
        session.invalidate();
        //回到登陆界面
        return "redirect:/login.html";
    }

    //没有权限访问
    @RequestMapping("nopermission")
    public String nopermission(){
        //跳转页面
        return "/common/nopermission";
    }

}
